package cn.leetcode;

import java.util.HashSet;
import java.util.Set;

public class Code128 {

    public static void main(String[] args) {
        int[] arr = {0,3,7,2,5,8,4,6,0,1};
        int i = longestConsecutive(arr);
        System.out.println(i);
    }


    public static int longestConsecutive(int[] nums) {
        int fin = 0;
        Set<Integer> set = new HashSet<>();
        for (int num : nums){
            set.add(num);
        }
        for (Integer i : set){
            int left = i - 1;
            if(!set.contains(left)){
                int a = 1;
                while (set.contains(++i)){
                    a++;
                }
                fin = Math.max(fin, a);
            }
        }
        return fin;
    }

}


